package com.evil.enterprise.controller;

import com.evil.common.core.entity.R;
import com.evil.common.file.dto.FileRespDTO;
import com.evil.common.file.dto.UploadReqDTO;
import com.evil.common.file.constant.OssConstant;
import com.evil.common.file.enums.BusTypeEnum;
import com.evil.file.api.RemoteFileService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 上传接口
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@RestController
@RequestMapping
@AllArgsConstructor
public class UploadController {

    private final RemoteFileService remoteFileService;

    /**
     * 上传文件
     *
     * @param uploadReqDTO uploadReqDTO
     * @return R
     */
    @PostMapping("/upload/file")
    public R<FileRespDTO> uploadFile(@Validated UploadReqDTO uploadReqDTO) {
        uploadReqDTO.setType(BusTypeEnum.PORTRAIT.getId());
        uploadReqDTO.setAllowContentType(OssConstant.UPLOAD_ALLOW_MIME_TYPE);
        uploadReqDTO.setAllowMaxSize(OssConstant.UPLOAD_FILE_SIZE);
        return R.success(remoteFileService.uploadFile(uploadReqDTO));
    }
}
